const R = require('ramda')

const commonFields = ['page', 'size', '_']

const commonFiledToNumber = R.compose(
  R.mapObjIndexed((v) => {
    if (/^-?\d*\.?\d+$/.test(v)) {
      return parseFloat(v)
    }
    return parseInt(v)
  }),
  R.pick(commonFields)
)

module.exports = (req, res, next) => {
  const query = req.query
  Object.assign(req.query, commonFiledToNumber(query))
  next()
}
